Pure Function
A pure function is a function that always:
- Produces the same output for the same input (deterministic behavior)
- Has no side effects
Rules of a Pure Function
| Rule | Description |
|---|---|
| 1. Same input → same output | Function must always return the same result for given arguments |
| 2. No side effects | It should not modify any external variable, object, DOM, or database |
| 3. No reliance on external mutable state | Shouldn’t depend on changing global variables or random values |
Math.random()impure function.